var express = require('express');
var request = require('request');
var router = express.Router();

/* GET users listing. */
router.post('/first', function (req, res, next) {
  res.header("Access-Control-Allow-Origin", req.headers.origin || '*');
  res.status(200);

  // var options = {
  //   method: 'post',
  //   url: 'https://qualityassurance-cmb-api-uat.hangseng.com/cmb-hasecorpapi-pa-ddi-cert-proxy/v1/activity-histories/activity-history/retrieve-detail',
  //   headers:
  //   {
  //     'cache-control': 'no-cache',
  //     Authorization: 'Basic QjJHVEVTVDU2NTJfODhfQVBJNTpwdTY4VzNGUFhuRWRUY1FyVW04QWRYRUFCVGlWL2hSMC9PSHpqU1JRTUZkSm9sOGlPaUJOaHA4Q04vYzI4dFZDQlZyejdrRmJCVVJSZy9yNFhiUEoyV29FaGxvL2VEQUV1UVgxY3l6MThEZzlSajBmWlpsMU4wUnRyZE04dzZURHNmajRlYkZHRW41MUY1WXpmTVc3d0dSbVNWVXZvTUltN0dsVGpYbXMxN1JBeFMvY3laeHFTVWI4MTdhdUJuUFE1eFJuVHlRcGZkT1h6OWxwLzMrVFIyNlRVRUZYVUwrbTNTVVJNcUVRemxrUFhYVjIrcytwVnY2dHpXbjRMcWx3Vk8rRVRwSE5KZXQyY2JZaEc4YjZmWUQyVWxKSVhzT3FiZnBEZEpsNjkvalVOSzBFQmxUalp5cU1JWndtb0tmTlg1Zm9IOEp0UkxmNW5OUEprNnB2Znc9PQ==',
  //     msgSignature: 'nu0Z+nRqZEiavESP5xlQNRsOWMb/yeQ+nQpRZd0x744cvDYp2LsvcKFGW8x8R+TTA09Ol45WE0Wbw0Pn7yNQ3JzZB27cK/1oGnMzOo9Omw6KruBU23nMRfiXJDbtiKCoUEcsRRxw3zfqkYR7zRbw9W6SZix64hutxPlRqanQVRmFsjlCvW7Mayz68+Bpj07s2NONEcIxkoSHj5rkAHKmt+nSHCxf3NRTsRnvBeAzir1UXbzod8fH4tgFf7m2nZTP79QVGT31/obzAmlH+Mb2wZkhZQJ02nqqB2T2MrOSNdifM/kt3kGlfjLOjJ+BDtdUNCFjWh+MZz3oO7L6Huzt8g==',
  //     profileId: 'HKHASE200014033883SUAPI5',
  //     msgTimestamp: '1548151012181',
  //     'Content-Type': 'application/json'
  //   },
  //   body: { acknowledgementId: 'NA2065740214' },
  //   json: true
  // };

  var options = {
    method: 'post',
    url: 'http://127.0.0.1:3000/forward'
  };

  var newReq = request(options, function (error, response, body) {
    if (error) throw new Error(error);
    console.log(body);
  });

  newReq.pipe(res);
});

module.exports = router;


